//
//  UITableViewCell+HDOwnerCellList.m
//  app
//
//  Created by D on 15/5/8.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HDOwnerCell.h"


static const CGFloat kCellMargin = 24.0f;
static const CGFloat kPictureHeight = 46.0f;
static const CGFloat kLableHeight = 30.0f;
static const CGFloat kLableWight = 140.0f;
static const CGFloat kPhoneNumberWight = 500.0f;
static const CGFloat kPhoneNumberHight = 80.0f;
static const CGFloat kWorkTimeWight = 580.0f;
static const CGFloat kWorkTimeHight =50.0f;
static const CGFloat kNickNameH = 26.0f;


@interface HDOwnerCell ()

@end

@implementation  HDOwnerCell

//-(void)drawRect:(CGRect)rect
//{
//    
//}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifie Sign:(int)sign Row:(int)row Uid:(NSString*)uid
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifie]) {
        
        self.frame = CGRectOf([self.ubo fx:UB_LEFT fy:UB_TOP], [self.ubo ow:UBO_WINDOW.width oh:44]);
        
        self.iconImage = @[@"wait_pay",@"wait_receive",@"wait_ping",@"tui"];
        self.iconName = @[@"待支付",@"待收货",@"待评价",@"全部订单"];
        
        if (sign == 1) {
            self.frame = CGRectOf([self.ubo fx:UB_LEFT fy:UB_TOP], [self.ubo ow:UBO_WINDOW.width oh:72]);
            self.tag = 0;

            UIImageView * face = [[UIImageView alloc]initWithFrame:CGRectOf([self.ubo fx:UB_1_2 ox:-64 fy:UB_1_2 oy:-29], [self.ubo ow:58 oh:58])];
            face.layer.masksToBounds = YES;
            face.layer.cornerRadius = face.bounds.size.width/2;
            
            if ([[SDImageCache sharedImageCache] imageFromDiskCacheForKey:@"user_Head"]) {
                
                [face setImage:[[SDImageCache sharedImageCache] imageFromDiskCacheForKey:@"user_Head"]];
            }else{
                
                if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"face"]length] > 1) {
                    [face sd_setImageWithURL:[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:@"face"]] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                        
                        NSLog(@"图片加载完成后做的事情");
                        NSData * data = UIImageJPEGRepresentation(image,1.0);
                        [[SDImageCache sharedImageCache] storeImage:image recalculateFromImage:YES imageData:data forKey:@"user_Head" toDisk:YES];
                        
                        
                    }];
                }else
                {
                    
                    if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"gender"]integerValue] == 1) {
                        [face setImage:[UIImage imageNamed:@"nick_img"]];
                    }else
                    {
                        [face setImage:[UIImage imageNamed:@"nick_img"]];
                    }
                    
                }
                
                
            }
            [self addSubview:face];
            
            
            UIImageView * circle = [[UIImageView alloc]init];
            circle.frame = CGRectOf([self.ubo fx:UB_1_2 ox:-65 fy:UB_1_2 oy:-30], [self.ubo ow:60 oh:60]);
            [circle setImage:[UIImage imageNamed:@"circle_gray_my"]];
            [self addSubview:circle];
            
            
            CGFloat nameW = [XCommon widthForString:[[NSUserDefaults standardUserDefaults]objectForKey:@"nickname"] fontSize:15];
            if (nameW > 128) {
                nameW = 128;
            }
#warning nameW 得改回来 暂时标记为128
            UILabel * name = [[UILabel alloc]initWithFrame:CGRectOf([face.ufo fx:1 ox:kCellMargin/3 fy:0 oy:4], [self.ubo ow:nameW oh:kNickNameH])];
            name.text = [[NSUserDefaults standardUserDefaults]objectForKey:@"nickname"];
//            name.text = @"这就是我名字";
            [name setFont:[UIFont systemFontOfSize:15]];
            [name setTextColor:[UIColor blackColor]];
            [self addSubview:name];
            
            
            UILabel * member = [[UILabel alloc]initWithFrame:CGRectOf([name.ufo fx:0 fy:1 oy:2], [self.ubo ow:128 oh:13])];
            member.text = [NSString stringWithFormat:@"会员号:%@",[[NSUserDefaults standardUserDefaults]objectForKey:@"uid"]];
            [member setFont:[UIFont systemFontOfSize:13]];
            [member setTextColor:[UIColor grayColor]];
            [self addSubview:member];
            if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"uid"]integerValue] == 0) {
                [member setHidden:YES];
            }
            
            
            UILabel * scores = [[UILabel alloc]initWithFrame:CGRectOf([member.ufo fx:0 fy:1 oy:4], [self.ubo ow:140 oh:13])];
            scores.text = [NSString stringWithFormat:@"积分:%@",[[NSUserDefaults standardUserDefaults]objectForKey:@"scores"]];
            [scores setFont:[UIFont systemFontOfSize:13]];
            [scores setTextColor:[UIColor grayColor]];
            [self addSubview:scores];
            
            
            
        }
        else if (sign == 2){
            if (row == 0) {
                
                self.tag = 1;
                self.frame = CGRectOf([self.ubo fx:UB_LEFT fy:UB_TOP], [self.ubo ow:UBO_WINDOW.width oh:64]);
                
                float fx = UB_1_4 * 0.5;
                for (int i = 0 ; i < 4; i++) {
                    
                    UIImageView * icon = [[UIImageView alloc]init];
                    icon.frame = CGRectOf([self.ubo fx:(i*2+1)*fx ox:-12 oy:12], [self.ubo ow: 24 oh:24]);
                    [icon setImage:[UIImage imageNamed:[self.iconImage objectAtIndex:i]]];
                    [self addSubview:icon];
                    
                    UILabel * iconLab = [[UILabel alloc]init];
                    iconLab.frame = CGRectOf([self.ubo fx:i*UB_1_4 ux:0 fy:1 oy:-28], [self.ubo ow:UBO_WINDOW.width/4 oh:15]);
                    iconLab.text = [self.iconName objectAtIndex:i];
                    [iconLab setTextColor:[UIColor blackColor]];
                    [iconLab setTintColor:[UIColor blackColor]];
                    UIFont * font = [UIFont systemFontOfSize:11];
                    [iconLab setFont:font];
                    [iconLab setTextAlignment:NSTextAlignmentCenter];
                    [self addSubview:iconLab];
                    
                    UIButton * btn = [[UIButton alloc]init];
                    btn.frame = CGRectOf([self.ubo fx:i*UB_1_4 ux:0 fy:0], [self.ubo fw:UB_WIDTH/4 uh:112]);
                    btn.tag = i;
                    btn.backgroundColor = [UIColor clearColor];
                    [btn addTarget:self action:@selector(clickCellButton:) forControlEvents:UIControlEventTouchUpInside];
                    [self addSubview:btn];
                    
                    
                    UIImageView * line = [[UIImageView alloc]init];
                    line.frame = CGRectOf([self.ubo fx:(i+1)*UB_1_4 ux:0 fy:0 uy:88-38], [self.ubo uw:1 uh:76]);
                    line.alpha = 0.25;
                    line.backgroundColor = [UIColor whiteColor];
                    [self addSubview:line];
                    
                    
                    
                    
                }
            }
            else if (row == 1) {
                
                self.tag = 2;
                
                self.image = [[UIImageView alloc]initWithFrame:CGRectOf([self.ubo fx:UB_LEFT ox:kCellMargin/2 fy:UB_1_2 oy:-kPictureHeight/4], [self.ubo ow:kPictureHeight/2 oh:kPictureHeight/2])];
                [self.image setImage:[UIImage imageNamed:@"service"]];
                [self addSubview:self.image];
                
                self.name = [[UILabel alloc]initWithFrame:CGRectOf([self.image.ufo fx:1 ox:8 fy:UB_1_2 oy:-kLableHeight/4], [self.ubo ow:kLableWight/2 oh:kLableHeight/2])];
                self.name.text = @"联系物业";
                [self.name setTextColor:[UIColor colorWithRed:68.0f/255.0f green:68.0f/255.0f blue:68.0f/255.0f alpha:1]];
                [self.name setFont:JKAppGlobleFontMenu];
                [self addSubview:self.name];
                
            }
            else if (row == 2){
                
                self.tag = 3;
                
                self.image = [[UIImageView alloc]initWithFrame:CGRectOf([self.ubo fx:UB_LEFT ox:kCellMargin/2 fy:UB_1_2 oy:-kPictureHeight/4], [self.ubo ow:kPictureHeight/2 oh:kPictureHeight/2])];
                [self.image setImage:[UIImage imageNamed:@"localtion"]];
                [self addSubview:self.image];
                
                self.name = [[UILabel alloc]initWithFrame:CGRectOf([self.image.ufo fx:1 ox:8 fy:UB_1_2 oy:-kLableHeight/4], [self.ubo ow:kLableWight/2 oh:kLableHeight/2])];
                self.name.text = @"我的小区";
                [self.name setTextColor:[UIColor colorWithRed:68.0f/255.0f green:68.0f/255.0f blue:68.0f/255.0f alpha:1]];
                [self.name setFont:JKAppGlobleFontMenu];
                [self addSubview:self.name];
                
                
                
            }
            else if (row == 3)
            {
                self.tag = 4;
                
                self.image = [[UIImageView alloc]initWithFrame:CGRectOf([self.ubo fx:UB_LEFT ox:kCellMargin/2 fy:UB_1_2 oy:-kPictureHeight/4], [self.ubo ow:kPictureHeight/2 oh:kPictureHeight/2])];
                [self.image setImage:[UIImage imageNamed:@"collect"]];
                [self addSubview:self.image];
                
                self.name = [[UILabel alloc]initWithFrame:CGRectOf([self.image.ufo fx:1 ox:8 fy:UB_1_2 oy:-kLableHeight/4], [self.ubo ow:110 oh:kLableHeight/2])];
                self.name.text = @"双明汇客服";
                [self.name setTextColor:[UIColor colorWithRed:68.0f/255.0f green:68.0f/255.0f blue:68.0f/255.0f alpha:1]];
                [self.name setFont:JKAppGlobleFontMenu];
                [self addSubview:self.name];
            }
            else if (row == 4){
                self.tag = 5;
                
                self.image = [[UIImageView alloc]initWithFrame:CGRectOf([self.ubo fx:UB_LEFT ox:kCellMargin/2 fy:UB_1_2 oy:-kPictureHeight/4], [self.ubo ow:kPictureHeight/2 oh:kPictureHeight/2])];
                [self.image setImage:[UIImage imageNamed:@"ic_info"]];
                [self addSubview:self.image];
                
                self.name = [[UILabel alloc]initWithFrame:CGRectOf([self.image.ufo fx:1 ox:8 fy:UB_1_2 oy:-kLableHeight/4], [self.ubo ow:90 oh:kLableHeight/2])];
                self.name.text = @"消息中心";
                [self.name setTextColor:[UIColor colorWithRed:68.0f/255.0f green:68.0f/255.0f blue:68.0f/255.0f alpha:1]];
                [self.name setFont:JKAppGlobleFontMenu];
                [self addSubview:self.name];
            
            }
 

        }
        else if (sign == 3){
        
            if (row == 0) {
                
                self.tag = 5;
                
                self.image = [[UIImageView alloc]initWithFrame:CGRectOf([self.ubo fx:UB_LEFT ox:kCellMargin/2 fy:UB_1_2 oy:-kPictureHeight/4], [self.ubo ow:kPictureHeight/2 oh:kPictureHeight/2])];
                [self.image setImage:[UIImage imageNamed:@"version"]];
                [self addSubview:self.image];
                
                self.name = [[UILabel alloc]initWithFrame:CGRectOf([self.image.ufo fx:1 ox:8 fy:UB_1_2 oy:-kLableHeight/4], [self.ubo ow:kLableWight/2 oh:kLableHeight/2])];
                self.name.text = @"当前版本";
                [self.name setTextColor:[UIColor colorWithRed:68.0f/255.0f green:68.0f/255.0f blue:68.0f/255.0f alpha:1]];
                [self.name setFont:JKAppGlobleFontMenu];
                [self addSubview:self.name];
                
                
                
                
                UILabel * version = [[UILabel alloc]initWithFrame:CGRectOf([self.ubo fx:1 ox:-64 fy:UB_1_2 oy:-6], [self.ubo ow:40 oh:12])];
                version.text = [NSString stringWithFormat:@"%@",APP_VERSION];
                [version setTextAlignment:NSTextAlignmentRight];
                [version setFont:[UIFont systemFontOfSize:14]];
                [version setTextColor:[UIColor grayColor]];
                [self addSubview:version];

                
            }
            
            
        }
        else if (sign == 4){
            
            self.tag = 6;
            
            UIImage * BGimage = [UIImage imageNamed:@"gray_01"];
            CGFloat top = 6;
            CGFloat bottom = 6;
            CGFloat left = 6;
            CGFloat right = 6;
            UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);
            BGimage = [BGimage resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
            
            CGFloat logoutW = UBO_WINDOW.width -24;
            UIButton * logoutBtn = [[UIButton alloc]initWithFrame:CGRectOf([self.ubo fx:UB_1_2 ox:-logoutW/2 fy:UB_1_2 oy:-20], [self.ubo ow:logoutW oh:40])];
            [logoutBtn setBackgroundImage:BGimage forState:UIControlStateNormal];
            [logoutBtn setTintColor:[UIColor whiteColor]];
            [logoutBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [logoutBtn setTitle:@"退出" forState:UIControlStateNormal];
            [logoutBtn addTarget:self action:@selector(loginout:) forControlEvents:UIControlEventTouchUpInside];
            [logoutBtn.titleLabel setFont:[UIFont systemFontOfSize:15]];
            [self addSubview:logoutBtn];
            
           
            
        }
       
        
        
    }
    return self;
}


-(void)clickCellButton:(UIButton*)sender
{
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(cellSelectClickHeaderButtonWithButton:)]) {
        [self.delegate cellSelectClickHeaderButtonWithButton:sender];
    }
    
    
}

-(void)loginout:(UIButton*)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(loginout)]) {
        [self.delegate loginout];
    }
}


@end












